﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TTQT;
using TTQT.TTQT_Code;
using TTQT.TTQT_Code.Info;
using System.Data.SqlClient;
public partial class Reports_TongHopBaoCao : MasterControl
{
    private int _dayIndex = 0;
    private int _day1Index = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            bindCN();
            bindPGD();
            bindGDV();
            cboLoaiAnChi.DataSourceID = "SqlDataSource1";
            cboLoaiAnChi.DataBind();
            //ddlDPH.Items.Add(new ListItem("Tất cả các đợt","0"));
            LoadReportList();
            ddlBaocao_SelectedIndexChanged(null, null);
            LoadYearList(DateTime.Now.Year);
            LoadMonthList(true, DateTime.Now.Month);
            ddlDay.SelectedValue = DateTime.Now.Day.ToString();
            ddlDay1.SelectedValue = DateTime.Now.Day.ToString();
            //LoadDayList(true, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Day);
        }
    }
    private void bindCN()
    {
        string brnCode = "";
        SqlConnection conn = new SqlConnection(TTQTCommon.DBConnectionString);
        SqlCommand comm = new SqlCommand("getMaCNByMaKhoGDV", conn);
        try
        {
            cboCN.DataBind();
            //Add parameter for Command
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.AddWithValue("@MaKhoGDV", UserInfo.MaKho);
            conn.Open();
            brnCode = TTQTCommon.ToString(comm.ExecuteScalar());
            cboCN.SelectedValue = brnCode;
        }
        catch (Exception ex)
        {
            // Writing log methods here.
        }
        finally
        {
            if (conn.State == ConnectionState.Open) conn.Close();
            conn.Dispose();
            comm.Dispose();
        }

    }
    private void bindPGD()
    {
        cboPGD.Items.Clear();
        dsPGD.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;

        dsPGD.SelectCommand = "MaKho_GetAllPGD_By_User_MaKho";

        dsPGD.SelectParameters.Clear();
        dsPGD.SelectParameters.Add(new Parameter("maKho"));
        dsPGD.SelectParameters["maKho"].DefaultValue = cboCN.SelectedValue;
        cboPGD.DataSourceID = "dsPGD";
        cboPGD.DataBind();
        cboPGD.Items.Add(new ListItem("------------------------", "0"));
    }
    private void bindGDV()
    {
        dsGDV.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        dsGDV.SelectCommand = "MaKho_GetAllGDV_By_MaPGD";
        dsGDV.SelectParameters.Clear();
        dsGDV.SelectParameters.Add(new Parameter("maKho"));
        dsGDV.SelectParameters["maKho"].DefaultValue = cboPGD.SelectedValue;
        cboPGD.DataValueField = "MaKho";
        cboGDV.DataTextField = "TenKho";
        cboGDV.DataSourceID = "dsGDV";

        cboGDV.DataBind();
        cboGDV.Items.Add(new ListItem("------------------------", "0"));
    }
    private void LoadReportList()
    {

        Report r = new Report();
        // Nếu là người dùng thuộc trung ương
        if (UserInfo.Brn_Code.Equals("000"))
        {
            ddlBaocao.Items.Clear();
            ddlBaocao.DataSource = r.GetbyUser(true, false, false, false);
            ddlBaocao.DataBind();
        }
        else // Nếu là người dùng thuộc chi nhánh/PGD (Có thể là CN đầu mối hoặc CN bình thường)
        {
            if (isRole("quychinhkhodaumoi")) // Nếu là quy chinh kho dau moi
            {
                ddlBaocao.Items.Clear();
                ddlBaocao.DataSource = r.GetbyUser(false, true, false, false);
                ddlBaocao.DataBind();
            }
            if (UserInfo.Pgd == 0 && (isRole("quychinh") || isRole("ksv") || isRole("adminCN"))) // là QC hoặc KSV CN 
            {
                ddlBaocao.Items.Clear();
                ddlBaocao.DataSource = r.GetbyUser(false, true, false, false);
                ddlBaocao.DataBind();
            }
            if (UserInfo.Pgd != 0 && (isRole("quychinh") || isRole("ksv"))) //là QC hoặc KSV PGD
            {
                ddlBaocao.Items.Clear();
                ddlBaocao.DataSource = r.GetbyUser(false, false, true, false);
                ddlBaocao.DataBind();
            }
            if (isRole("gdv")) // Nếu là gdv
            {
                ddlBaocao.Items.Clear();
                ddlBaocao.DataSource = r.GetbyUser(false, false, false, true);
                ddlBaocao.DataBind();
            }
        }
        //Nếu thuộc cn đầu mối thì cho xem thêm BC5
        if (UserInfo.Brn_Code.Equals("990") || UserInfo.Brn_Code.Equals("561") || UserInfo.Brn_Code.Equals("140"))
        {
            ddlBaocao.Items.Add(new ListItem("BC5_Báo cáo tình hình sử dụng ấn chỉ của các đơn vị đầu mối", "BC5"));
        }
        ddlBaocao.Items.Add(new ListItem("__________ Lựa chọn báo cáo ___________", "BC"));
        ddlBaocao.SelectedValue = "BC";
    }

    private void LoadYearList(int cur)
    {
        ddlYear.Items.Clear();
        ddlYear1.Items.Clear();

        for (int i = 1990; i < 2091; i++)
        {
            ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            ddlYear1.Items.Add(new ListItem(i.ToString(), i.ToString()));

        }
        cur = cur < 1990 ? 1990 : cur;
        cur = cur > 2090 ? 2090 : cur;
        ddlYear_SelectedIndexChanged(null, null);
        ddlYear1_SelectedIndexChanged(null, null);
        ddlYear.SelectedIndex = cur - 1990;
        ddlYear1.SelectedIndex = cur - 1990;
        int days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
        int curday = DateTime.Now.Day;
        curday = curday < 1 ? 1 : curday;
        curday = curday > days ? days : curday;
        if (ddlDay.Items.Count > 0)
            ddlDay.SelectedIndex = curday - 1;
        if (ddlDay1.Items.Count > 0)
            ddlDay1.SelectedIndex = curday - 1;
    }

    private void LoadDayList(bool ismonth, int month, int year, int cur)
    {
        ddlDay.Items.Clear();
        ddlDay1.Items.Clear();
        if (!ismonth)
        {
            ddlDay.Enabled = false;
            ddlDay1.Enabled = false;
        }
        else
        {
            ddlDay.Enabled = true;
            ddlDay1.Enabled = true;

            int days = DateTime.DaysInMonth(year, month);
            for (int i = 1; i <= days; i++)
            {
                ddlDay.Items.Add(new ListItem(i.ToString(), i.ToString()));
                ddlDay1.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            cur = cur < 1 ? 1 : cur;
            cur = cur > days ? days : cur;
            ddlDay.SelectedIndex = cur - 1;
            ddlDay1.SelectedIndex = cur - 1;
        }
    }

    private void LoadMonthList(bool ismonth, int cur)
    {
        ddlMonth.Items.Clear();
        ddlMonth1.Items.Clear();
        if (ismonth)
        {
            for (int i = 1; i < 13; i++)
            {
                ddlMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
                ddlMonth1.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            cur = cur < 1 ? 1 : cur;
            cur = cur > 12 ? 12 : cur;
            ddlMonth_SelectedIndexChanged(null, null);
            ddlMonth1_SelectedIndexChanged(null, null);
            ddlMonth.SelectedIndex = cur - 1;
            ddlMonth1.SelectedIndex = cur - 1;
            int days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
            int curday = DateTime.Now.Day;
            curday = curday < 1 ? 1 : curday;
            curday = curday > days ? days : curday;
            if (ddlDay.Items.Count > 0)
                ddlDay.SelectedIndex = curday - 1;
            if (ddlDay1.Items.Count > 0)
                ddlDay1.SelectedIndex = curday - 1;

        }
    }
    protected void btnXem_Click(object sender, EventArgs e)
    {
        try
        {
            Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue);
        }
        catch
        {
            MyWebUtils.MyWebUtil.alert(this.Page, "Tu ngay khong hop le");
            return;
        }
        try
        {
            Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue);
        }
        catch
        {
            MyWebUtils.MyWebUtil.alert(this.Page, "Den ngay khong hop le");
            return;
        }
        btnTH_Click(null, null);
        lblError.Visible = false;
        Session["MaAnChi"] = cboLoaiAnChi.SelectedItem;
        Session["KhoAnChi"] = cboMaKho.SelectedItem;
        if (cboMaKho.SelectedValue == "0")
        {
            Session["TENBAOCAO"] = "TỔNG HỢP BẢNG KÊ GIAO DỊCH ";
            Session["TUKHO"] = "";
            Session["DENKHO"] = "";
        }
        else
        {
            Session["TENBAOCAO"] = "BẢNG KÊ GIAO DỊCH ";
            Session["TUKHO"] = "Từ kho : " + cboMaKho.SelectedItem;
            Session["DENKHO"] = "Đến kho :" + cboMaKho.SelectedItem;
        }
        if (ddlTinhChat.SelectedValue == "0")
        {
            Session["TINHCHAT"] = "QUAN TRỌNG";
        }
        else
        {
            Session["TINHCHAT"] = "THƯỜNG HUY ĐỘNG VỐN";
        }
        Session["FromDate1"] = ddlDay.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue;
        Session["ToDate1"] = ddlDay1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlYear1.SelectedValue;

        string sFileRptName = "";
        Report r = new Report();
        r.selectByID(null, ddlBaocao.SelectedValue);
        //Thao.Nguyen modified 20100804
        if (!string.IsNullOrEmpty(r.TenFile))
        {
            sFileRptName = "REPORTS/" + r.TenFile;

            if (r.ReportID.Equals("BC14")) // Đac biet. Neu chon bao cao GDV
            {

                if (cboGDV.Items.Count < 1)
                {
                    MyWebUtils.MyWebUtil.alert(this.Page, "Chua chon GDV");
                    return;
                }
                try
                {
                    Session["PGD"] = cboPGD.SelectedItem.Text;
                    Session["GDV"] = cboGDV.SelectedItem.Text;//.Substring(cboGDV.Text.IndexOf("- ") + 2);
                }
                catch
                {
                    Session["GDV"] = cboGDV.Text;
                }
                DateTime ngayChon =
                    Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" +
                                       ddlDay.SelectedValue);
                string dauKy = ngayChon.ToString("yyyy/MM/dd");
                string ngayTonDauKy = ngayChon.AddDays(-1).ToString("yyyy/MM/dd");
                ngayChon =
                    Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" +
                                       ddlDay1.SelectedValue);
                string cuoiKy = ngayChon.ToString("yyyy/MM/dd");
                sFileRptName = "REPORTS/BC14_BangKeTheoDoiAnChi_GDV.aspx?LoaiAnChi=" + cboLoaiAnChi.SelectedValue +
                               "&GDV=" + cboGDV.SelectedValue + "&dauKy=" + dauKy.Replace('/', '-') + "&cuoiKy=" +
                               cuoiKy.Replace('/', '-') + "&ngayTonDauKy=" + ngayTonDauKy.Replace('/', '-');
            }
            if (r.ReportID.Equals("BC15")) // Đac biet. Neu chon bao cao QUY CHINH
            {
                try
                {
                    Session["GDV"] = cboCN.SelectedItem.Text.Substring(cboCN.SelectedItem.Text.IndexOf("-") + 1);//.Substring(cboGDV.Text.IndexOf("- ") + 2);
                }
                catch
                {
                    Session["GDV"] = cboCN.SelectedItem.Text;
                }
                DateTime ngayChon =
                    Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" +
                                       ddlDay.SelectedValue);
                string dauKy = ngayChon.ToString("yyyy/MM/dd");
                string ngayTonDauKy = ngayChon.AddDays(-1).ToString("yyyy/MM/dd");
                ngayChon =
                    Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" +
                                       ddlDay1.SelectedValue);
                string cuoiKy = ngayChon.ToString("yyyy/MM/dd");
                sFileRptName = "REPORTS/BC15_BangKeTheoDoiAnChi_QUYCHINH.aspx?CN=" + cboCN.SelectedValue + "&LoaiAnChi=" + cboLoaiAnChi.SelectedValue +
                               "&GDV=" + cboGDV.SelectedValue + "&dauKy=" + dauKy.Replace('/', '-') + "&cuoiKy=" +
                               cuoiKy.Replace('/', '-') + "&ngayTonDauKy=" + ngayTonDauKy.Replace('/', '-');
            }
            Response.Write("<script>");
            Response.Write("window.open('" + sFileRptName + "')");
            Response.Write("</script>");
        }
    }
    protected void btnThoat_Click(object sender, EventArgs e)
    {
        Response.Redirect(navigateUrl(0));
    }

    private void showAllRow()
    {
        tinhChatAnChi.Visible =
            dotPhatHanh.Visible =
            loaiAnChi.Visible = tuNgay.Visible = denNgay.Visible = khoDen.Visible = pgd.Visible = gdv.Visible = true;
    }
    private void hideAllRow()
    {
        tinhChatAnChi.Visible =
            dotPhatHanh.Visible =
            loaiAnChi.Visible = tuNgay.Visible = denNgay.Visible = khoDen.Visible = pgd.Visible = gdv.Visible = false;
    }
    protected void ddlBaocao_SelectedIndexChanged(object sender, EventArgs e)
    {
        // nếu chọn báo cáo GDV thì đặt luôn ngày là ngày hôm trước. Không thì đặt ngày hiện tại

        /*
        try
        {
            if(ddlBaocao.SelectedValue.Equals("BC14"))
            {
                ddlDay1.SelectedValue = DateTime.Now.AddDays(-1).Day.ToString();
            }
            else
            {
                ddlDay1.SelectedValue = DateTime.Now.Day.ToString();
            }
        }
        catch (Exception)
        {
        }
        */
        try
        {
            cboCN.DataBind();
            cboCN.SelectedValue = UserInfo.MaKho;
        }
        catch (Exception exx)
        {
            string i;
            //cboCN.DataBind();
        }
        lblError.Visible = false;
        hideAllRow();
        Report r = new Report();
        r.selectByID(null, ddlBaocao.SelectedValue);
        tinhChatAnChi.Visible = r.TinhChatAC;
        dotPhatHanh.Visible = r.DotPhatHanh;
        loaiAnChi.Visible = r.LoaiAnChi;
        tuNgay.Visible = r.TuNgay;
        denNgay.Visible = r.DenNgay;
        khoDen.Visible = r.KhoDen;
        //Thao.Nguyen modified 20100805
        //Thay đổi việc lựa chọn chi nhánh theo user
        CN.Visible = Session["Brn_Code"].Equals("000") && r.CN;
        //CN.Visible = r.CN;
        pgd.Visible = r.PGD;
        gdv.Visible = r.GDV;
        /*
                if (ddlBaocao.SelectedValue == "BC031")
                {
                    setVisible(true, false, false, true, true, true, false);
                    lblKhoDen.Text = "Kho nhận";
                    lblTuNgay.Text = "Từ Ngày";
                }
                else if ((ddlBaocao.SelectedValue == "BC032") || (ddlBaocao.SelectedValue == "BC5") || (ddlBaocao.SelectedValue == "BC11"))
                {
                    setVisible(true, true, true, true, true, false, false);
                    lblTuNgay.Text = "Từ Ngày";
                }
                else if (ddlBaocao.SelectedValue == "BC16")
                {
                    setVisible(true, false, false, true, true, true, false);
                    lblKhoDen.Text = "Kho xuất";
                    lblTuNgay.Text = "Từ Ngày";
                }
                else if ((ddlBaocao.SelectedValue == "BC2") || (ddlBaocao.SelectedValue == "BC012") || (ddlBaocao.SelectedValue == "BC7") || (ddlBaocao.SelectedValue == "BC11") || (ddlBaocao.SelectedValue == "BC4"))
                {
                    setVisible(true, true, true, true, true, false, false);
                    lblTuNgay.Text = "Từ Ngày";
                }
                else if ((ddlBaocao.SelectedValue == "BC09") || (ddlBaocao.SelectedValue == "BC13"))
                {
                    setVisible(true, false, false, true, true, false, false);
                    lblTuNgay.Text = "Từ Ngày";
                }
                //Thao.Nguyen added to invisible controls
                else if (ddlBaocao.SelectedValue.Equals("BC9"))
                {
                    if (Session["Brn_Code"].ToString().Equals("000"))
                    {
                        setVisible(true, false, true, true, false, false, false);
                    }
                    else
                    {
                        setVisible(true, true, false, true, false, false, false);
                    }
                    lblTuNgay.Text = "Ngày";
                }
                else if (ddlBaocao.SelectedValue.Equals("BC12"))
                {
                    setVisible(true, true, true, false, true, false, true);
                }
                else
                {
                    showAllRow();
                    lblTuNgay.Text = "Từ Ngày";
                }
        */
    }

    protected void btnTH_Click(object sender, EventArgs e)
    {
        string fromDate = "", toDate = "";
        DateTime f, t;
        try
        {

            f = Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue);
            fromDate =
                TTQTCommon.convertDateString(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" +
                                             ddlDay.SelectedValue);

        }
        catch
        {
            MyWebUtils.MyWebUtil.alert(this.Page, "Tu ngay khong hop le");
            return;
        }
        try
        {
            t = Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue);
            t.AddHours(23);
            toDate =
               TTQTCommon.convertDateString(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" +
                                            ddlDay1.SelectedValue);
        }
        catch
        {
            MyWebUtils.MyWebUtil.alert(this.Page, "Den ngay khong hop le");
            return;
        }
        string store = "";
        int kq = -1;
        SqlConnection conn = new SqlConnection(TTQTCommon.DBConnectionString);
        SqlCommand comm = new SqlCommand();
        switch (ddlBaocao.SelectedValue)
        {
            case "BC":
                {
                    lblError.Visible = true;
                    lblError.Text = "Bạn phải chọn báo cáo để tổng hợp!";
                    return;
                }
            case "BC1":
                {
                    string makho = "000";
                    Session["MaKho"] = makho;
                    store = "_BM01_BaoCaoSeriACBiMat1New";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC2":
                {
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    string tenchinhanh = string.Empty;
                    store = "_BM01_BaoCaoSeriACBiMat1New";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC3":
                {
                    //if (cboMaKho.SelectedValue != "0")
                    //{
                    //    store = "_BM08_TinhHinhSuDungACChiNhanh";
                    //    comm = new SqlCommand(store, conn);
                    //    comm.CommandType = CommandType.StoredProcedure;
                    //    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    //    comm.Parameters.AddWithValue("@Brn_Code", cboMaKho.SelectedValue);
                    //    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    //    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    //    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    //    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    //    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    //    break;
                    //}
                    //else
                    {
                        store = "_BC3_TinhHinhSuDungACHeThong";
                        comm = new SqlCommand(store, conn);
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                        comm.Parameters.AddWithValue("@Brn_Code", UserInfo.Brn_Code);
                        comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                        comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                        comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                        comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                        comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                        //comm.Parameters.AddWithValue("@FromDate", fromDate);
                        //comm.Parameters.AddWithValue("@ToDate", toDate);
                        //comm.Parameters.AddWithValue("@FromDate", f);
                        //comm.Parameters.AddWithValue("@ToDate", t);
                        break;
                    }
                }
            case "BC4":
                {
                    store = "_BC4_TinhHinhSuDungACChiNhanh";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@Brn_Code", cboCN.SelectedValue);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    DateTime d =
                        Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" +
                                           ddlDay.SelectedValue);
                    d = d.AddDays(-1);
                    comm.Parameters.AddWithValue("@FromDate", d);
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC5":
                {
                    //if (cboMaKho.SelectedValue != "0")
                    //{
                    //    store = "_BM08_TinhHinhSuDungACChiNhanh";
                    //    comm = new SqlCommand(store, conn);
                    //    comm.CommandType = CommandType.StoredProcedure;
                    //    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    //    comm.Parameters.AddWithValue("@Brn_Code", cboMaKho.SelectedValue);
                    //    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    //    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    //    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    //    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    //    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    //    break;
                    //}
                    //else
                    {
                        store = "_BC5_TinhHinhSuDungACCnDauMoi";
                        comm = new SqlCommand(store, conn);
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                        comm.Parameters.AddWithValue("@Brn_Code", UserInfo.Brn_Code);
                        comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                        comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                        comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                        comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                        comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                        break;
                    }
                }
            case "BC6":
                {
                    store = "_BC1_BangKeGiaoDichChoNhapKho";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;

                    comm.Parameters.AddWithValue("@Ngay", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@LoaiAnChi", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@KhoXuat", UserInfo.MaKho);
                    comm.Parameters.AddWithValue("@UserId", UserInfo.userName);
                    break;
                }
            case "BC012":
                {
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    string tenchinhanh = string.Empty;
                    store = "_BM01_BaoCaoSeriACBiMat1New";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    Session["MaKho"] = makho;
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC16":
                {
                    store = "_BC16_BangKeGiaoDichNhapKho";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@KhoNhan", cboCN.SelectedValue);
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"].ToString());
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    comm.Parameters.AddWithValue("@KhoXuat", cboCN.SelectedValue);
                    break;
                }
            case "BC31":
                {
                    store = "_BC31_BangKeGiaoDichXuatKho";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@KhoNhan", cboCN.SelectedValue);
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"].ToString());
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    comm.Parameters.AddWithValue("@KhoXuat", cboCN.SelectedValue);
                    break;
                }
            case "BC032":
                {
                    store = "_BM032_TinhHinhSuDungACHeThong";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }

            case "BC7":
                {
                    store = "_BM05_DieuChuyenAnChi";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC18":
                {
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    string tenchinhanh = string.Empty;
                    store = "_BC18_DieuChuyenAnChiTaiChiNhanh";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC8":
                {
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    store = "_BM06_BangTheoDoiAnChiToanHeThong";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC9":
                {
                    string dangChon = cboLoaiAnChi.SelectedValue;
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    //store = "_BM06_BangTheoDoiAnChiMauChiNhanh";
                    store = "_BM06_BangTheoDoiAnChiMauChiNhanhNew";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    //comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    //comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    //comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@Date", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC10":
            case "BC11":
                {
                    //store = "_BM07_TieuHuyAnChi";
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    Session["MaKho"] = makho;
                    store = "_BM07_TieuHuyAnChi";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.Visible ? cboLoaiAnChi.SelectedValue : "");

                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC09":
                {
                    store = "_BM09_BaoCaoGDXuatKhachHang";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC13":
                {
                    store = "_BM10_AnChiCapLaiChoKH";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC12":
                {
                    if (cboGDV.Items.Count < 1)
                    {
                        MyWebUtils.MyWebUtil.alert(this.Page, "Chua chon GDV");
                        return;
                    }
                    store = "_BM10_AnChiCapLaiChoKH";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@FromDate", Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlDay.SelectedValue));
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
            case "BC14": // Bang ke theo doi an chi cua GDV
                {
                    store = "LayTenChiNhanh_TheoTenDangNhap";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@User_name", UserInfo.userName);
                    break;
                }
            case "BC15":// Bang ke theo doi an chi quy chinh
                {
                    store = "LayTenChiNhanh_TheoTenDangNhap";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@User_name", UserInfo.userName);
                    break;
                }
            case "BC17":
                {
                    //string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    string makho = CN.Visible ? cboCN.SelectedValue.ToString() : this.UserInfo.MaKho;
                    Session["MaKho"] = makho;
                    store = "BC17_BaoCaoTonKhoAnChi";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKho", makho);
                    comm.Parameters.AddWithValue("@TinhChatAC", ddlTinhChat.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    comm.Parameters.AddWithValue("Date", DateTime.Now);
                    break;
                }
            case "BC100":
                {
                    //string makho = CN.Visible ? cboCN.SelectedValue.ToString() : DataAccessObject.instance().GetMaKhoByUserID(Session["UserName"].ToString());
                    string makho = CN.Visible ? cboCN.SelectedValue : this.UserInfo.MaKho;
                    Session["MaKho"] = makho;
                    store = "BC100_TinhHinhSuDungAnChiPGD";
                    comm = new SqlCommand(store, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@UserId", Session["UserName"]);
                    comm.Parameters.AddWithValue("@MaKhoPGD", cboPGD.SelectedValue);
                    comm.Parameters.AddWithValue("@LoaiAC", cboLoaiAnChi.SelectedValue);
                    comm.Parameters.AddWithValue("@Dot", ddlDPH.SelectedValue);
                    DateTime d =
                         Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlMonth.SelectedValue + "/" +
                                            ddlDay.SelectedValue);
                    d = d.AddDays(-1);
                    comm.Parameters.AddWithValue("@FromDate", d);
                    comm.Parameters.AddWithValue("@ToDate", Convert.ToDateTime(ddlYear1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlDay1.SelectedValue));
                    break;
                }
        }
        try
        {
            conn.Open();
            comm.Connection = conn;
            comm.ExecuteScalar();
            kq = 1;

            // Lay Ten CN
            comm.Parameters.Clear();
            comm.CommandType = CommandType.StoredProcedure;
            if (ddlBaocao.SelectedValue.Equals("BC4") || ddlBaocao.SelectedValue.Equals("BC100"))
            {
                comm.CommandText = "LayTenKho_TheoMa";
                comm.Parameters.AddWithValue("@makho", cboCN.SelectedValue);
            }
            else
            {
                comm.CommandText = "LayTenChiNhanh_TheoTenDangNhap";
                comm.Parameters.AddWithValue("@User_name", UserInfo.userName);
            }

            string tenCN = comm.ExecuteScalar().ToString();
            if (!string.IsNullOrEmpty(tenCN))
                Session["TenChiNhanh"] = tenCN;
            if (ddlBaocao.SelectedValue.Equals("BC100"))
            {
                comm.Parameters.Clear();
                comm.CommandType = CommandType.StoredProcedure;
                comm.CommandText = "LayTenKho_TheoMa";
                comm.Parameters.AddWithValue("@makho", cboPGD.SelectedValue);
                tenCN = comm.ExecuteScalar().ToString();
                if (!string.IsNullOrEmpty(tenCN))
                    Session["TenPGD"] = tenCN;
            }
        }
        catch (Exception ex)
        {
            kq = -1;
        }
        finally
        {
            conn.Close();
        }
        if (kq == -1)
        {
            lblError.Visible = true;
            lblError.Text = "Có lỗi tổng hợp báo cáo!";
            return;
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = "Đã tổng hợp xong báo cáo!";
            return;
        }
    }

    protected void cboPGD_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGDV();
    }
    protected void cboCN_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindPGD();
    }

    private int GetDaysInMonth(int month, int year)
    {
        if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month ||
        10 == month || 12 == month)
        {
            return 31;
        }
        if (2 == month)
        {
            // Kiểm tra năm nhuận
            if (0 == (year % 4))
            {
                //Nếu date chia hết cho 400, là năm nhuận
                //Mặt khác, nếu chia hết cho 100 là năm thường
                if (0 == (year % 400))
                {
                    return 29;
                }
                if (0 == (year % 100))
                {
                    return 28;
                }
                //Chia het cho 4 nhưng ko chia hết cho 100 hoặc 400 là năm nhuận
                return 29;
            }
            // Không phải năm nhuận
            return 28;
        }
        return 30;
    }

    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            _dayIndex = ddlDay.SelectedIndex;
            int daysOfMonth = GetDaysInMonth(int.Parse(ddlMonth.SelectedValue), int.Parse(ddlYear.SelectedValue));
            FillDays(ddlDay, daysOfMonth);
            ddlDay.SelectedIndex = _dayIndex;
        }
        catch (Exception ex)
        {

        }
    }
    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            _dayIndex = ddlDay.SelectedIndex;
            int daysOfMonth = GetDaysInMonth(int.Parse(ddlMonth.SelectedValue), int.Parse(ddlYear.SelectedValue));
            FillDays(ddlDay, daysOfMonth);
            ddlDay.SelectedIndex = _dayIndex;
        }
        catch (Exception ex)
        {

        }
    }
    protected void ddlMonth1_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int daysOfMonth = GetDaysInMonth(int.Parse(ddlMonth1.SelectedValue), int.Parse(ddlYear1.SelectedValue));
            FillDays(ddlDay1, daysOfMonth);
            ddlDay1.SelectedIndex = _day1Index;
        }
        catch (Exception ex)
        {

        }
    }
    protected void ddlYear1_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int daysOfMonth = GetDaysInMonth(int.Parse(ddlMonth1.SelectedValue), int.Parse(ddlYear1.SelectedValue));
            FillDays(ddlDay1, daysOfMonth);
            ddlDay1.SelectedIndex = _day1Index;
        }
        catch (Exception ex)
        {

        }
    }

    private void FillDays(DropDownList dropDownList, int daysOfMonth)
    {
        try
        {
            dropDownList.Items.Clear();
            for (int i = 0; i < daysOfMonth; i++)
            {
                dropDownList.Items.Add((i + 1).ToString());
            }
        }
        catch (Exception ex)
        {

        }
    }
    protected void ddlDay_SelectedIndexChanged(object sender, EventArgs e)
    {
        _dayIndex = ddlDay.SelectedIndex;
    }
    protected void ddlDay1_SelectedIndexChanged(object sender, EventArgs e)
    {
        _day1Index = ddlDay1.SelectedIndex;
    }
}
